﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace primenumber
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("十万以内的质数：");
            bool primen = true;
            //已知1不是质数,2是质数，i从3开始取值
            Console.Write("2  ");
            int temp = 1;
            for (int i = 3; i <= 100000; i++)
            {
                if (i%2==1)
                {
                    for (int j = 2; j < i; j++)
                    {
                        if (i % j != 0)
                        {
                            primen = true;
                        }
                        else
                        {
                            primen = false;
                            break;
                        }                       
                    }
                    if (primen)
                    {
                        Console.Write(i + "  ");
                        temp++;
                        if (temp % 10 == 0)
                        {
                            Console.WriteLine();
                        }
                    }
                }
            }
            Console.WriteLine();
            Console.WriteLine("总个数为："+temp);
            Console.ReadKey();
        }
    }
}
